<?php include 'head.php'; ?>

    <title>新增用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>

<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-header">新增用户</div>
        <div class="layui-card-body">
            <form class="layui-form" action="" onsubmit="return false">
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名(用户名)</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">再输入一次</label>
                    <div class="layui-input-block">
                        <input type="password" name="password2" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="gender" value="男" title="男" checked><input type="radio" name="gender" value="女" title="女"><input type="radio" name="gender" value="保密" title="保密">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生日</label>
                    <div class="layui-input-block">
                        <input type="text" name="birthday" id="date" placeholder="请输入生日" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="number" name="tel" placeholder="请输入电话" class="layui-input" value="<?php echo $row['tel']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="email" name="mail" placeholder="请输入邮箱" class="layui-input" value="<?php echo $row['mail']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">QQ</label>
                    <div class="layui-input-block">
                        <input type="number" name="qq" placeholder="请输入QQ" class="layui-input" value="<?php echo $row['qq']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">微信</label>
                    <div class="layui-input-block">
                        <input type="text" name="wechat" placeholder="请输入微信" class="layui-input" value="<?php echo $row['wechat']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="address" placeholder="请输入地址" class="layui-input" value="<?php echo $row['address']; ?>">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">立即提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>
<script src="/component/layui/layui.js"></script>

<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery', 'button', 'popup'], function() {
        var $ = layui.jquery;
        var form = layui.form;
        var button = layui.button;
        var popup = layui.popup;
        
        // 登 录 提 交
        window.onkeypress = function(e) { if (e.keyCode == 13) { $('[lay-submit]').click(); } }
form.on('submit(formDemo)', function(data) {
            var pass = $('#password').val();
            var pass2 = $('#password2').val();
            if (pass == '' || pass2 == '') {
                popup.failure("密码不能为空！");
                return false;
            }
            if (pass != pass2) {
                popup.failure("两次输入的密码不一致！");
                return false;
            }

            /// 按钮加载动画
            var load = button.load({
                elem: '.pear-btn-primary'
            });
            /// 提交
            $.ajax({
                url: './ajax.php?act=adduser',
                type: "POST",
                timeout: "5000",
                data: data.field,
                success: function(data) {
                    load.stop();
                    if (data.code == "200") {
                        popup.success(data.msg);
                    } else {
                        popup.failure(data.msg);
                    }
                },
                error: function(XMLResponse) {
                    load.stop();
                    popup.failure("提交异常");
                }
            });

            return false;
        });
    })
</script>

</html>